package com.itheima.hmshopping.app.controller;
import com.itheima.hmshopping.app.service.SmsHomeAdvertiseService;
import com.itheima.hmshopping.entity.SmsHomeAdvertise;
import com.itheima.hmshopping.util.HmPage;
import com.itheima.hmshopping.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("home/advertise")
public class SmsHomeAdvertiseController {
    @Autowired
    private SmsHomeAdvertiseService smsHomeAdvertiseService;
    /**
     * 添加广告
     * @param smsHomeAdvertise
     * @return
     */
    @PostMapping("create")
    private R create(@RequestBody SmsHomeAdvertise smsHomeAdvertise){

         smsHomeAdvertiseService.create(smsHomeAdvertise);
         return R.succeed("ok","");
    }

    /**
     * 删除广告
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public R delete(@RequestParam("ids")List<Integer>ids){
        smsHomeAdvertiseService.delete(ids);
        return R.succeed("ok","");
    }

    /**
     * 分页查询广告
     * @param endTime
     * @param name
     * @param pageNum
     * @param pageSize
     * @param type
     * @return
     */
    @GetMapping("list")
    public R list(@RequestParam(value = "endTime", required = false) String endTime,
                  @RequestParam(value = "name", required = false) String name,
                  @RequestParam(value = "pageNum", required = false) Integer pageNum,
                  @RequestParam(value = "pageSize", required = false) Integer pageSize,
                  @RequestParam(value = "type", required = false) Integer type) {
       HmPage hmPage= smsHomeAdvertiseService.list(endTime, name, pageNum, pageSize, type);
       return R.succeed(hmPage,"ok");
    }

    /**
     * 修改上下线状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("update/status/{id}")
    public R updateStatus(@PathVariable Integer id,
                          @RequestParam(value = "status", required = false) Integer status) {
       smsHomeAdvertiseService.updateStatus(id, status);
        return R.succeed("ok","");
    }


    /**
     * 修改广告
     * @param id
     * @param smsHomeAdvertise
     * @return
     */
    @PostMapping("update/{id}")
    public R updateFlashPromotion(@PathVariable Integer id, @RequestBody SmsHomeAdvertise smsHomeAdvertise) {
       smsHomeAdvertiseService.update(id, smsHomeAdvertise);
        return R.succeed("ok","");
    }

    /**
     * 获取广告详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R getFlashPromotion(@PathVariable Integer id) {
       SmsHomeAdvertise smsHomeAdvertise= smsHomeAdvertiseService.getOne(id);
        return R.succeed(smsHomeAdvertise,"");
    }


}
